<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.7.2/axios.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/js-cookie/3.0.5/js.cookie.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
    <script src="../../js/http.js"></script>
    <title>添加商品</title>
    <link rel="stylesheet" href="../../css/index.css">

    <style>
        ul {
            display: flex;
            flex-direction: column;
        }
    </style>
</head>

<body>
<div id="root">
    <ul>
        <li><input id="title" name="" type="text"></li>
        <li><input id="img_big_logo" name="" type="file"></li>
        <li><input id="price" name="" type="text"></li>
        <li><input id="goods_number" name="" type="text"></li>
        <li><input id="category" name="" type="text"></li>
        <li>
            <button @click="release">发布</button>
        </li>
    </ul>


</div>
<script>
  let vm = new Vue({
    el: '#root',
    data() {
      return {
        cartList: null,
      };
    },
    methods: {
      release() {
        const title = document.getElementById('title').value;
        const img_big_logo = document.getElementById('img_big_logo').files[0];
        const price = document.getElementById('price').value * 1;
        const goods_number = document.getElementById('goods_number').value * 1;
        const category = document.getElementById('category').value;
        console.log(title, img_big_logo, price, goods_number, category);

        ajax({
          url: '/admin/goods/add',
          method: 'POST',

          headers: {
            'Authorization': Cookies.get('token'),
            'Content-Type': 'application/json',
          },

          data: {
            title,
            img_big_logo,
            price,
            goods_number,
            category,
          },
        }).then((r) => {
          console.log(r.data);
          if (r.data.code === 0) {
            alert('请重新登录!');
            location.href = '../../login.html';
          }
        });
      },

    },
    mounted() {
      const that = this;

    },
  });
</script>
</body>
</html>